import {baseEffects, baseReducers, baseState} from "../../../models/baseModel";
import {getAllDeviceType} from "../../../models/deviceType";
import * as request from "../../../services/CommonHttpService";
import PageHelper from "utils/pageHelper";
import AppService from "../../../common/AppService";

export default {
  namespace: 'deviceStatistics',

  state: {
    ...baseState,
    deviceStatisticData: [],
    onlineEcgSize: 2,
    onlineBpSize: 3,
    onlineSpoSize: 6,
  },

  reducers: {
    ...baseReducers,
  },

  effects: {

    ...baseEffects,

    * initStatisticData({payload}, {call,put}) {
      let result = yield call(request.commonGet, getBaseUrl(), {},{}, AppService.deviceUrl);
      const deviceStatisticData = result.map(value => {
        let  Device;
        switch (value.deviceType) {
          case 'BP_DEVICE':
            Device = "mlnx血压";
            break;
          case 'XM_BP':
            Device = "星脉血压";
            break;
          case 'ZK_BP':
            Device = "正康血压";
            break;
          case 'ECG_DEVICE':
            Device = "mlnx心电";
            break;
          case 'MP_DEVICE':
            Device = "多参心电";
            break;
          case 'SPO_DEVICE':
            Device = "血氧";
            break;
          case 'SBP_DEVICE':
            Device = "带血压血氧";
            break;
          case  'XIAOLOU_SPO_DEVICE':
            Device = "小楼血氧";
        }
        return {
          Device: Device,
          "空闲": Math.round(value.totalCount - value.onlineCount),
          "使用": Math.round(value.onlineCount)
        };
      });
      yield put({
        type: 'initState',
        payload: {deviceStatisticData}
      });
    },


  }

}

function getBaseUrl() {
  return "/device/count/";
}

